<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('商品信息列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>商品类别：</label>
                            <input type="hidden" name="goodsTypeId" id="treeId"/>
                            <input type="text" onclick="selectGoodsTypeTree()" id="treeName" name="treeName" readonly="true">
                        </li>
                        <li>
                            <label>商品编码：</label>
                            <input type="text" name="goodsCode"/>
                        </li>
                        <li>
                            <label>商品名称：</label>
                            <input type="text" name="goodsName"/>
                        </li>
                        <li>
                            <label>商品条码：</label>
                            <input type="text" name="goodsBarcode"/>
                        </li>
                        <li>
                            <label style="width: 95px">成本价锁定：</label>
                            <select name="isCost" th:with="type=${@dict.getType('sys_yes_no')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="shop:goods:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.editTab()" shiro:hasPermission="shop:goods:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="shop:goods:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
<!--            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="shop:goods:export">
                <i class="fa fa-download"></i> 导出
            </a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editPriceFlag = [[${@permission.hasPermi('shop:goods:editPrice')}]];
    var editFlag = [[${@permission.hasPermi('shop:goods:edit')}]];
    var removeFlag = [[${@permission.hasPermi('shop:goods:remove')}]];
    var changeIsCostFlag = [[${@permission.hasPermi('shop:goods:changeIsCost')}]];
    var goodsUnitDatas = [[${@dict.getType('MEASURING_UNIT')}]];
    var isCostDatas = [[${@dict.getType('sys_yes_no')}]];
    var prefix = ctx + "shop/goods";

    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            sortName: "t.createTime",
            sortOrder: "desc",
            modalName: "商品信息",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'goodsTypeName',
                    title: '商品类别'
                },
                {
                    field: 'goodsCode',
                    title: '商品编码'
                },
                {
                    field: 'goodsName',
                    title: '商品名称'
                },
                {
                    field: 'goodsBarcode',
                    title: '商品条码'
                },
                {
                    field: 'goodsSearchstandard',
                    title: '商品规格',
                    visible: false
                },
                {
                    field: 'goodsColor',
                    title: '商品颜色'
                },
                {
                    field: 'storageName',
                    title: '所属库位'
                },
                {
                    field: 'goodsUnit',
                    title: '商品单位',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(goodsUnitDatas, value);
                    }
                },
                {
                    field: 'goodsWeight',
                    title: '商品重量(单位:KG)',
                    visible: false
                },
                {
                    field: 'costPrice',
                    title: '成本价'
                },
                {
                    field: 'retailPrice',
                    title: '零售价'
                },
                {
                    field: 'sellingPrice',
                    title: '销售价'
                },
                {
                    field: 'wholesalePrice',
                    title: '批发价'
                },
                {
                    field: 'isCost',
                    title: '成本价锁定',
                    formatter: function(value, row, index) {
                        /*return $.table.selectDictLabel(isCostDatas, value);*/
                        if($.common.isEmpty(changeIsCostFlag)){
                            return statusTools(row);
                        }else{
                            return value;
                        }
                    }
                },
                {
                    field: 'stockNumber',
                    title: '库存数量'
                },
                {
                    field: 'safetyStock',
                    title: '安全库存'
                },
                {
                    field: 'remark',
                    title: '备注',
                    visible: false
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editPriceFlag + '" href="javascript:void(0)" onclick="onEditPrice(\'' + row.id + '\')"><i class="fa fa-edit"></i>价格调整</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /* 成本价锁定状态显示 */
    function statusTools(row) {
        if (row.isCost == 'N') {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
        }
    }

    /* 成本价锁定-停用 */
    function disable(id) {
        $.modal.confirm("确认要解锁吗？", function() {
            $.operate.post(prefix + "/changeIsCost", { "id": id, "isCost": 'N' });
        })
    }

    /* 成本价锁定启用 */
    function enable(id) {
        $.modal.confirm("确认要锁定吗？", function() {
            $.operate.post(prefix + "/changeIsCost", { "id": id, "isCost": 'Y' });
        })
    }

    /* 价格调整 */
    function onEditPrice(id){
        var url = prefix + '/editPrice/'+id;
        $.modal.open("商品移库", url);
    }

    var goodsTypePrefix = ctx + "shop/goodsType"
    /*商品类别-选择父商品类别树*/
    function selectGoodsTypeTree() {
        var options = {
            title: '商品类别选择',
            width: "380",
            url: goodsTypePrefix + "/selectGoodsTypeTree/" + $("#treeId").val(),
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero){
        var body = layer.getChildFrame('body', index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        layer.close(index);
    }
</script>
</body>
</html>